home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / src / linux-headers-2.6.28-15 / include / linux / pmic_adc.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-09  |  11.1 KB  |  456 lines

  1. /*
  2.  * Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
  3.  */
  4.  
  5. /*
  6.  * The code contained herein is licensed under the GNU Lesser General
  7.  * Public License.  You may obtain a copy of the GNU Lesser General
  8.  * Public License Version 2.1 or later at the following locations:
  9.  *
  10.  * http://www.opensource.org/licenses/lgpl-license.html
  11.  * http://www.gnu.org/copyleft/lgpl.html
  12.  */
  13.  
  14. #ifndef __ASM_ARCH_MXC_PMIC_ADC_H__
  15. #define __ASM_ARCH_MXC_PMIC_ADC_H__
  16.  
  17. /*!
  18.  * @defgroup PMIC_ADC PMIC Digitizer Driver
  19.  * @ingroup PMIC_DRVRS
  20.  */
  21.  
  22. /*!
  23.  * @file arch-mxc/pmic_adc.h
  24.  * @brief This is the header of PMIC ADC driver.
  25.  *
  26.  * @ingroup PMIC_ADC
  27.  */
  28.  
  29. #include <linux/ioctl.h>
  30. #include <linux/pmic_status.h>
  31. #include <linux/pmic_external.h>
  32.  
  33. /*!
  34.  * @name IOCTL user space interface
  35.  */
  36.  
  37. /*! @{ */
  38. /*!
  39.  * Initialize ADC.
  40.  * Argument type: none.
  41.  */
  42. #define PMIC_ADC_INIT                   _IO('p', 0xb0)
  43. /*!
  44.  * De-initialize ADC.
  45.  * Argument type: none.
  46.  */
  47. #define PMIC_ADC_DEINIT                 _IO('p', 0xb1)
  48. /*!
  49.  * Convert one channel.
  50.  * Argument type: pointer to t_adc_convert_param.
  51.  */
  52. #define PMIC_ADC_CONVERT                _IOWR('p', 0xb2, int)
  53. /*!
  54.  * Convert one channel eight samples.
  55.  * Argument type: pointer to t_adc_convert_param.
  56.  */
  57. #define PMIC_ADC_CONVERT_8X             _IOWR('p', 0xb3, int)
  58. /*!
  59.  * Convert multiple channels.
  60.  * Argument type: pointer to t_adc_convert_param.
  61.  */
  62. #define PMIC_ADC_CONVERT_MULTICHANNEL   _IOWR('p', 0xb4, int)
  63. /*!
  64.  * Set touch screen operation mode.
  65.  * Argument type: t_touch_mode.
  66.  */
  67. #define PMIC_ADC_SET_TOUCH_MODE         _IOW('p', 0xb5, int)
  68. /*!
  69.  * Get touch screen operation mode.
  70.  * Argument type: pointer to t_touch_mode.
  71.  */
  72. #define PMIC_ADC_GET_TOUCH_MODE         _IOR('p', 0xb6, int)
  73. /*!
  74.  * Get touch screen sample.
  75.  * Argument type: pointer to t_touch_sample.
  76.  */
  77. #define PMIC_ADC_GET_TOUCH_SAMPLE       _IOWR('p', 0xb7, int)
  78. /*!
  79.  * Get battery current.
  80.  * Argument type: pointer to unsigned short.
  81.  */
  82. #define PMIC_ADC_GET_BATTERY_CURRENT    _IOR('p', 0xb8, int)
  83. /*!
  84.  * Activate comparator.
  85.  * Argument type: pointer to t_adc_comp_param.
  86.  */
  87. #define PMIC_ADC_ACTIVATE_COMPARATOR    _IOW('p', 0xb9, int)
  88. /*!
  89.  * De-active comparator.
  90.  * Argument type: none.
  91.  */
  92. #define PMIC_ADC_DEACTIVE_COMPARATOR    _IOW('p', 0xba, int)
  93.  
  94. /*!
  95.  * Install touch screen read interface.
  96.  */
  97. #define TOUCH_SCREEN_READ_INSTALL       _IOWR('D',4, int)
  98. /*!
  99.  * Remove touch screen read interface.
  100.  */
  101. #define TOUCH_SCREEN_READ_UNINSTALL     _IOWR('D',5, int)
  102.  
  103. /*! @{ */
  104. /*!
  105.  * @name Touch Screen minimum and maximum values
  106.  */
  107. #define TS_X_MIN                80    /*! < Minimum X */
  108. #define TS_Y_MIN                80    /*! < Minimum Y */
  109.  
  110. #define TS_X_MAX                1000    /*! < Maximum X */
  111. #define TS_Y_MAX                1000    /*! < Maximum Y */
  112. /*! @} */
  113. /*!
  114.  * This enumeration defines input channels for PMIC ADC
  115.  */
  116.  
  117. typedef enum {
  118.     BATTERY_VOLTAGE,
  119.     BATTERY_CURRENT,
  120.     CHARGE_VOLTAGE,
  121.     CHARGE_CURRENT,
  122.     APPLICATION_SUPPLY,
  123.     TS_X_POS1,
  124.     TS_X_POS2,
  125.     TS_Y_POS1,
  126.     TS_Y_POS2,
  127.     GEN_PURPOSE_AD4,
  128.     GEN_PURPOSE_AD5,
  129.     GEN_PURPOSE_AD6,
  130.     GEN_PURPOSE_AD7,
  131.     GEN_PURPOSE_AD8,
  132.     GEN_PURPOSE_AD9,
  133.     GEN_PURPOSE_AD10,
  134.     GEN_PURPOSE_AD11,
  135.     USB_ID,
  136.     LICELL,
  137.     RAWEXTBPLUSSENSE,
  138.     MPBSENSE,
  139.     BATSENSE,
  140.     GND,
  141.     THERMISTOR,
  142.     DIE_TEMP
  143. } t_channel;
  144.  
  145. /*!
  146.  * This enumeration defines reason of ADC Comparator interrupt.
  147.  */
  148. typedef enum {
  149.     /*!
  150.      * Greater than WHIGH
  151.      */
  152.     GTWHIGH,
  153.     /*!
  154.      * Less than WLOW
  155.      */
  156.     LTWLOW,
  157. } t_comp_exception;
  158.  
  159. /*!
  160.  * ADC comparator callback function type
  161.  */
  162. typedef void (*t_comparator_cb) (t_comp_exception reason);
  163.  
  164. /*!
  165.  * This enumeration defines the touch screen operation modes.
  166.  */
  167. typedef enum {
  168.     /*!
  169.      * Touch Screen X position
  170.      */
  171.     TS_X_POSITION = 0,
  172.     /*!
  173.      * Touch Screen Y position
  174.      */
  175.     TS_Y_POSITION = 1,
  176.     /*!
  177.      * Pressure
  178.      */
  179.     TS_PRESSURE = 2,
  180.     /*!
  181.      * Plate X
  182.      */
  183.     TS_PLATE_X = 3,
  184.     /*!
  185.      * Plate Y
  186.      */
  187.     TS_PLATE_Y = 4,
  188.     /*!
  189.      * Standby
  190.      */
  191.     TS_STANDBY = 5,
  192.     /*!
  193.      * No touch screen, TSX1, TSX2, TSY1 and TSY2 are used as  general
  194.      * purpose A/D inputs.
  195.      */
  196.     TS_NONE = 6,
  197. } t_touch_mode;
  198. /*!
  199.  * This structure is used to report touch screen value.
  200.  */
  201. typedef struct {
  202. /*!
  203.      * Touch Screen X position
  204.      */
  205.     unsigned int x_position;
  206.     /*!
  207.      * Touch Screen X position1
  208.      */
  209.     unsigned int x_position1;
  210.     /*!
  211.      * Touch Screen X position2
  212.      */
  213.     unsigned int x_position2;
  214.     /*!
  215.      * Touch Screen X position3
  216.      */
  217.     unsigned int x_position3;
  218.     /*!
  219.      * Touch Screen Y position
  220.      */
  221.     unsigned int y_position;
  222.     /*!
  223.      * Touch Screen Y position1
  224.      */
  225.     unsigned int y_position1;
  226.     /*!
  227.      * Touch Screen Y position2
  228.      */
  229.     unsigned int y_position2;
  230.     /*!
  231.      * Touch Screen Y position3
  232.      */
  233.     unsigned int y_position3;
  234.     /*!
  235.      * Touch Screen contact value
  236.      */
  237.     unsigned int contact_resistance;
  238. } t_touch_screen;
  239.  
  240. /*!
  241.  * This enumeration defines ADC conversion modes.
  242.  */
  243. typedef enum {
  244.     /*!
  245.      * Sample 8 channels, 1 sample per channel
  246.      */
  247.     ADC_8CHAN_1X = 0,
  248.     /*!
  249.      * Sample 1 channel 8 times
  250.      */
  251.     ADC_1CHAN_8X,
  252. } t_conversion_mode;
  253.  
  254. /*!
  255.  * This structure is used with IOCTL code \a PMIC_ADC_CONVERT,
  256.  * \a PMIC_ADC_CONVERT_8X and \a PMIC_ADC_CONVERT_MULTICHANNEL.
  257.  */
  258.  
  259. typedef struct {
  260.     /*!
  261.      * channel or channels to be sampled.
  262.      */
  263.     t_channel channel;
  264.     /*!
  265.      * holds up to 16 sampling results
  266.      */
  267.     unsigned short result[16];
  268. } t_adc_convert_param;
  269.  
  270. /*!
  271.  * This structure is used to activate/deactivate ADC comparator.
  272.  */
  273. typedef struct {
  274.     /*!
  275.      * wlow.
  276.      */
  277.     unsigned char wlow;
  278.     /*!
  279.      * whigh.
  280.      */
  281.     unsigned char whigh;
  282.     /*!
  283.      * channel to monitor
  284.      */
  285.     t_channel channel;
  286.     /*!
  287.      * callback function.
  288.      */
  289.     t_comparator_cb callback;
  290. } t_adc_comp_param;
  291.  
  292. /* EXPORTED FUNCTIONS */
  293.  
  294. #ifdef __KERNEL__
  295. /*!
  296.  * This function initializes all ADC registers with default values. This
  297.  * function also registers the interrupt events.
  298.  *
  299.  * @return       This function returns PMIC_SUCCESS if successful.
  300.  */
  301. PMIC_STATUS pmic_adc_init(void);
  302.  
  303. /*!
  304.  * This function disables the ADC, de-registers the interrupt events.
  305.  *
  306.  * @return       This function returns PMIC_SUCCESS if successful.
  307.  */
  308. PMIC_STATUS pmic_adc_deinit(void);
  309.  
  310. /*!
  311.  * This function triggers a conversion and returns one sampling result of one
  312.  * channel.
  313.  *
  314.  * @param        channel   The channel to be sampled
  315.  * @param        result    The pointer to the conversion result. The memory
  316.  *                         should be allocated by the caller of this function.
  317.  *
  318.  * @return       This function returns PMIC_SUCCESS if successful.
  319.  */
  320.  
  321. PMIC_STATUS pmic_adc_convert(t_channel channel, unsigned short *result);
  322.  
  323. /*!
  324.  * This function triggers a conversion and returns eight sampling results of
  325.  * one channel.
  326.  *
  327.  * @param        channel   The channel to be sampled
  328.  * @param        result    The pointer to array to store eight sampling results.
  329.  *                         The memory should be allocated by the caller of this
  330.  *                         function.
  331.  *
  332.  * @return       This function returns PMIC_SUCCESS if successful.
  333.  */
  334.  
  335. PMIC_STATUS pmic_adc_convert_8x(t_channel channel, unsigned short *result);
  336.  
  337. /*!
  338.  * This function triggers a conversion and returns sampling results of each
  339.  * specified channel.
  340.  *
  341.  * @param        channels  This input parameter is bitmap to specify channels
  342.  *                         to be sampled.
  343.  * @param        result    The pointer to array to store sampling result.
  344.  *                         The order of the result in the array is from lowest
  345.  *                         channel number to highest channel number of the
  346.  *                         sampled channels.
  347.  *                         The memory should be allocated by the caller of this
  348.  *                         function.
  349.  *               Note that the behavior of this function might differ
  350.  *               from one platform to another regarding especially
  351.  *               channels order.
  352.  *
  353.  * @return       This function returns PMIC_SUCCESS if successful.
  354.  */
  355.  
  356. PMIC_STATUS pmic_adc_convert_multichnnel(t_channel channels,
  357.                      unsigned short *result);
  358.  
  359. /*!
  360.  * This function sets touch screen operation mode.
  361.  *
  362.  * @param        touch_mode   Touch screen operation mode.
  363.  *
  364.  * @return       This function returns PMIC_SUCCESS if successful.
  365.  */
  366. PMIC_STATUS pmic_adc_set_touch_mode(t_touch_mode touch_mode);
  367.  
  368. /*!
  369.  * This function retrieves the current touch screen operation mode.
  370.  *
  371.  * @param        touch_mode   Pointer to the retrieved touch screen operation
  372.  *                            mode.
  373.  *
  374.  * @return       This function returns PMIC_SUCCESS if successful.
  375.  */
  376. PMIC_STATUS pmic_adc_get_touch_mode(t_touch_mode * touch_mode);
  377.  
  378. /*!
  379.  * This function retrieves the current touch screen operation mode.
  380.  *
  381.  * @param        touch_sample Pointer to touch sample.
  382.  * @param        wait    Indicates if this function needs to block or not.
  383.  *
  384.  * @return       This function returns PMIC_SUCCESS if successful.
  385.  */
  386. PMIC_STATUS pmic_adc_get_touch_sample(t_touch_screen * ts_value, int wait);
  387.  
  388. /*!
  389.  * This function starts a Battery Current mode conversion.
  390.  *
  391.  * @param        mode      Conversion mode.
  392.  * @param        result    Battery Current measurement result.
  393.  *                         if \a mode = ADC_8CHAN_1X, the result is \n
  394.  *                             result[0] = (BATTP - BATT_I) \n
  395.  *                         if \a mode = ADC_1CHAN_8X, the result is \n
  396.  *                             result[0] = BATTP \n
  397.  *                             result[1] = BATT_I \n
  398.  *                             result[2] = BATTP \n
  399.  *                             result[3] = BATT_I \n
  400.  *                             result[4] = BATTP \n
  401.  *                             result[5] = BATT_I \n
  402.  *                             result[6] = BATTP \n
  403.  *                             result[7] = BATT_I
  404.  *
  405.  * @return       This function returns PMIC_SUCCESS if successful.
  406.  */
  407. PMIC_STATUS pmic_adc_get_battery_current(t_conversion_mode mode,
  408.                      unsigned short *result);
  409.  
  410. /*!
  411.  * This function actives the comparator.  When comparator is activated and ADC
  412.  * is enabled, the 8th converted value will be digitally compared against the
  413.  * window defined by WLOW and WHIGH registers.
  414.  *
  415.  * @param        low      Comparison window low threshold (WLOW).
  416.  * @param        high     Comparison window high threshold (WHIGH).
  417.  * @param        callback Callback function to be called when the converted
  418.  *                        value is beyond the comparison window.  The callback
  419.  *                        function will pass a parameter of type
  420.  *                        \b t_comp_expection to indicate the reason of
  421.  *                        comparator exception.
  422.  *
  423.  * @return       This function returns PMIC_SUCCESS if successful.
  424.  */
  425.  
  426. PMIC_STATUS pmic_adc_active_comparator(unsigned char low,
  427.                        unsigned char high,
  428.                        t_channel channel,
  429.                        t_comparator_cb callback);
  430.  
  431. /*!
  432.  * This function de-actives the comparator.
  433.  *
  434.  * @return       This function returns PMIC_SUCCESS if successful.
  435.  */
  436. PMIC_STATUS pmic_adc_deactive_comparator(void);
  437.  
  438. /*!
  439.  * This function enables the touch screen read interface.
  440.  *
  441.  * @return       This function returns 0 if successful.
  442.  */
  443. PMIC_STATUS pmic_adc_install_ts(void);
  444.  
  445. /*!
  446.  * This function disables the touch screen read interface.
  447.  *
  448.  * @return       This function returns 0 if successful.
  449.  */
  450. PMIC_STATUS pmic_adc_remove_ts(void);
  451.  
  452. int is_pmic_adc_ready(void);
  453.  
  454. #endif                /* _KERNEL */
  455. #endif                /* __ASM_ARCH_MXC_PMIC_ADC_H__ */
  456.